<?php
$this->breadcrumbs = array(
    '产品中心' => array(''),
    '综合产品管理',
);
Yii::app()->clientScript->registerScript('search', "
$('form.search-form').submit(function(){
	$.fn.yiiGridView.update('product-base-grid', {
		data: $(this).serialize()
	});
	return false;
});
$('#delete-button').click(function(){
    var selects = $.fn.yiiGridView.getSelection('product-base-grid');
    if(selects==''){
        alert('请选中记录进行操作！');
    }else{
       if(window.confirm('您确定要删除吗？')){
            $.fn.yiiGridView.update('product-base-grid', {
		type:'POST',
		url:'" . $this->rewriteCreateUrl('delete') . "',
                                    data:{id:selects},
		success:function(data) {
                    $.fn.yiiGridView.update('product-base-grid');
                    //afterDelete(th,true,data);
		},
		error:function() {
                    //afterDelete(th,false);
		}
            });
            return false;
       }
    }
});
");
?>
<div class="box corners shadow">
    <div class="box-header">
        <h2>综合产品管理</h2>
        <div class="box-header-ctrls">	
            <a href="javascript:void(null);" title="" class="close"><!-- --></a>
        </div>
    </div>

    <div class="box-content" id="contacts-1a">
        <div class="inbox-sf">
            <form class="search-form">
                <?php
                echo CHtml::dropDownList('ProductBase[p_game]', '', array('' => '所有') + ProductCategory::model()->getGameSelect(), array('class' => 'tips', 'title' => '游戏'));
                echo CHtml::dropDownList('ProductBase[p_type]', '', array('' => '所有') + Yii::app()->params['model_array'], array('class' => 'tips', 'title' => '产品类型'));
                $this->Widget('ext.searchField.searchFieldWidget', array(
                    'initText' => '',
                    'titleText' => '输入产品名称查询',
                    'inputName' =>  'ProductBase[p_name]',
                    'inputId' =>  'ProductBase_p_name_search',
                ));
                
                ?>                
                <input type="submit" name="" value="查询" class="inbox-sf-search-btn" />
            </form>
            <a class="button black fr tip" id="delete-button" href="javascript:void(null);" title="选中数据进行删除！">
                <span>批量删除</span>
            </a>
            <a class="button black fr" href="<?php echo $this->rewriteCreateUrl('create') ?>">
                <span>添加产品</span>
            </a>
        </div> 
        <?php
        $this->widget('zii.widgets.grid.CGridView', array(
            'id' => 'product-base-grid',
            'dataProvider' => $model->search(),
            'cssFile' => '',
            'htmlOptions' => array('class' => ''),
            'template' => '<div id="loading"></div>{summary}{items}{pager}',
            'itemsCssClass' => 'tablebox',
            //'ajaxUpdate' => false,
            'pager' => array(//通过pager设置样式   默认为CLinkPager
                'prevPageLabel' => '<<',
                'firstPageLabel' => '首页', //first,last 在默认样式中为{display:none}及不显示，通过样式{display:inline}即可
                'nextPageLabel' => '>>',
                'lastPageLabel' => '末页',
                'header' => '',
                'htmlOptions' => array('class' => 'box-nav')
            ),
            'emptyText' => '<font size="4" color="red">请设置条件进行查询！</font>',
            'selectableRows' => 2,
            'columns' => array(
                array(
                    'class' => 'CCheckBoxColumn',
                    'header' => '全选',
                    'value' => '$data->id',
                    'id' => 'delete',
                    'htmlOptions' => array('style' => 'width:20px')
                ),
                array(
                    'name' => 'p_game',
                    'value' => '  ProductCategory::model()->getGameNameById($data->p_game)'
                ),
                 array(
                    'name' => 'p_type',
                    'value' => 'Yii::app()->params["model_array"][$data->p_type]',
                ),
                
                array(
                    'name' => 'p_name',
                    'value' => 'ProductBase::model()->createInput("p_name", $data->id, $data->p_name)',
                ),
                array(
                    'name' => 'p_price',
                    'value' => 'ProductBase::model()->createInput("p_price", $data->id, $data->p_price)',
                ),
                array(
                    'name' => 'p_rebate',
                    'value' => 'ProductBase::model()->createInput("p_rebate", $data->id, $data->p_rebate)',
                ),
                'p_quntity',
               
                'name' => 'p_time',
                array(
                    'type' => 'raw',
                    'htmlOptions' => array('style' => 'width:140px'),
                    'value' => 'Yii::app()->controller->getColumnOptions($data->id,"ProductBase")',
                ),
            ),
        ));
        ?>         
    </div><!-- END ".box-content" --> 
</div>
<script>
    function copyRow(obj){//复制
        if(confirm("确定要复制这条记录！")){
            $("#product-base-grid").addClass("grid-view-loading");
            $.post("<?php echo $this->createUrl('ajax'); ?>", {id:$(obj).attr("rel-id"), action:"copy"}, function(data){
                if(data){
                    location.reload();
                    $("#product-base-grid").removeClass("grid-view-loading");
                }
            });
        }
        
    }
    function updateField(obj){//更新单个数据内容
        $(obj).addClass("loading");
        $.post("<?php echo $this->createUrl('ajax'); ?>", {field:$(obj).attr("rel-field"), id:$(obj).attr("rel-id"), fieldVal:$(obj).val(), action:"updateField"}, function(data){
            if(data){
                $(obj).removeClass("loading").addClass("ok");
            }else{
                $(obj).removeClass("loading").addClass("error");
            }
        });
    }
</script>